<template>
  <div class="tenantHome tenantHome2">
    <dingyue/>
    <!-- <div class="tenantSwiper"> -->
      <!-- <swiper class="swiper" :indicator-dots="indicatorDots" indicator-color="rgba(255, 255, 255, .55)" indicator-active-color="#fff"	circular="true" :autoplay="autoplay" :interval="interval" :duration="duration">
        <swiper-item  v-for="item in bannerList" :key="item.ids" @click="checkBanner(item)">
          <img class="swiper-item" :src="item.pic">
        </swiper-item>
      </swiper> -->
      <ad unit-id="adunit-8b2d0fe4d5908760" ad-type="video" ad-theme="white"></ad>
    <!-- </div> -->
    <div class="user-infor">
      <div class="left1">
        <div class="user">
          <img :src="userInfo.avatar" alt="">
        </div>
        <div class="center">
          <div>{{userInfo.unickname}}</div>
          <img v-if="baseUrl" :src="baseUrl+'my/zuke.png'" alt="">
        </div>
      </div>
      
      <div class="right">
        <img @click="showType" v-if="baseUrl" :src="baseUrl+'tenant/home/zuke.png'" alt="">
        <div class="rightType" v-if="isshowtype">
          <div class="one" @click="checkType(1)">管理员</div>
          <div @click="checkType(2)">业主</div>
        </div>
      </div>
    </div>
    <div class="tenant-content">
      <swiper v-if="isnone>0" class="content-swiper" :indicator-dots="indicatorDots" indicator-color="rgba(190, 190, 190, .55)" indicator-active-color="#BEBEBE"	circular="true">
        <swiper-item v-for="(item,index) in tenantInfo" :key="index">
          <div class="content-top">
            <div class="flex k20">
              <div class="address-imag">
                <img v-if="baseUrl" :src="baseUrl+'tenant/home/address.png'" alt="">
              </div>
             <div class="flex k20">
                   <div class="address" style="width:50%">
                      {{item.address}}
                   </div>
                   <div style="width:50%" class="flex">
                       <div class="k33 textCenter" @click="jiaozu(index)" v-if="tenantInfoTwo[index].cycle == 5 && tenantInfoTwo[index].payrenttype ==0">
                           <img :src="baseUrl+'twoicon/jiaozu.png'" alt="" class="k20" style="width:40rpx;height:40rpx">
                           <p class="textStyle">交租</p>
                       </div>
                       <div class="k33 textCenter" @click="jiaozu2(index)" v-if="tenantInfoTwo[index].cycle !=5 && tenantInfoTwo[index].payrenttype ==0">
                         <img :src="baseUrl+'twoicon/jiaozu.png'" alt="" class="k20" style="width:40rpx;height:40rpx">
                           <p class="textStyle">交租</p>
                       </div> 
                      
                      <div class="k33 textCenter" @click="dianfei(index)" v-if="tenantInfoTwo[index].powersn && item.roommate=='0'">
                           <img :src="baseUrl+'twoicon/dianfei.png'" alt="" class="k20" style="width:40rpx;height:40rpx">
                           <p class="textStyle">充电费</p>
                       </div>
                      <div class="k33 textCenter"  @click="call" style="display:none">
                           <img :src="baseUrl+'twoicon/phone.png'" alt="" class="k20" style="width:40rpx;height:40rpx">
                           <p class="textStyle">联系管家</p>
                       </div>
                   </div>
             </div>
            </div>
          </div>
          <div class="centent-center">
          <div class="dianbao" v-if=" tenantInfoTwo[index].powersn">
             <span class="dianfeiyue">{{tenantInfoTwo[index].electricitybalance}}度</span>
             <img :src="baseUrl+'twoicon/dianbao.png'" alt="" class="k20" style="width:120rpx;height:120rpx">
             <p style="text-algin:center;color:blue;margin-left:5rpx;color:#1782d2;font-weight:600">电费余量</p>
          </div>
            <div class="last">
              授权剩余
            </div>
            <div :class="['power', item.power > 10 ? '' : 'nopower']">
              <div class="chi">
                {{item.power}}%
                <div class="jindu" :style="{width:item.power+'%'}"></div>
              </div>
              <div class="shu"></div>
            </div>
            <div :class="['last-time', item.days < 15 || tem.days == 15 ? 'redcolor':'']">
              {{item.days}}
              <span>天</span>
            </div>
            <div class="open-door">
              <img class="openB" @click="openDoor(0,item,)" v-if="item.locknumber" :src="baseUrl+'tenant/home/openBig.png'">
              <img class="openS" @click="openDoor(1,item)" v-if="item.roomlocknumber" :src="baseUrl+'tenant/home/openSmail.png'">
            </div>
          </div>
          <div class="getpassword" v-if="item.locknumber">
            <div class="getmima" @click="gotocheck(item)">
              获取密码
            </div>
          </div>
        </swiper-item>
      </swiper>
      <div v-if="isnone<1" class="none">
        <img v-if="baseUrl" :src="baseUrl+'imgs/imgs/none.png'" alt="">
      </div>
    </div>
    <uni-popup ref="popup1" type="center">
      <div class="checkPassword">
        <div class="close" @click="closePupop(1)">
          <img v-if="baseUrl" :src="baseUrl+'order/close.png'" alt="" srcset="">
        </div>
        <div class="top">选择密码</div>
        <div class="bigBtn" @click="getPassword(0)">大门密码</div>
        <div class="smalBtn" @click="getPassword(1)">小门密码</div>
      </div>
    </uni-popup>
    <!-- 开锁成功 -->
    <uni-popup ref="popup2" type="center">
      <div class="open-success">
        <img v-if="baseUrl" :src="baseUrl+'opendoor/success.png'" alt="">
        <div class="text1">开锁成功</div>
        <div class="text2">开锁成功请开门</div>
        <button type="submit" @click="closePupop(2)">确定</button>
      </div>
    </uni-popup>
    <!-- 获取密码成功 -->
    <uni-popup ref="popup3" type="center">
      <div class="mima-success">
        <img v-if="baseUrl" :src="baseUrl+'opendoor/success.png'" alt="">
        <div class="text1">{{password}}</div>
        <div class="text2">请输完密码后请按门锁右下角的“#”开门 温馨提示：本密码使用一次后失效</div>
        <button class="btn1" type="submit" @click="closePupop(3)">确定</button>
        <!-- <button class="btn2" type="submit">密码无法开门请点我</button> -->
      </div>
    </uni-popup>
    <!-- 提醒打开蓝牙 -->
    <uni-popup ref="popup4" type="center">
      <div class="lanya">
        <img v-if="baseUrl" :src="baseUrl+'opendoor/jg.png'" alt="">
        <div class="text1 text">请靠近门锁打开蓝牙</div>
        <div class="text">并按门锁任意键激活</div>
        <button class="btn1" type="submit" @click="closePupop(4)">确定</button>
      </div>
    </uni-popup>
    <!-- 提醒初级用户 -->
    <uni-popup ref="popup7" type="center">
      <div class="lanya2">
        <img v-if="baseUrl" :src="baseUrl+'opendoor/jg.png'" alt="">
        <div class="text text1">您的房间为初级用户，无法开门。如需开门服务，请联系房东开通高级用户服务</div>
        <button class="btn1" type="submit" @click="closePupop(7)">确定</button>
      </div>
    </uni-popup>
     <uni-popup ref="popup8" type="center">
      <div class="edit">
        <div class="close" @click="closePopup">
          <img v-if="baseUrl" :src="baseUrl + 'order/close.png'" alt="" srcset="" />
        </div>
        <div class="edit-top">交租模式</div>
          <uni-forms ref="form" :modelValue="formData" :rules="rules">
           <div style="display:flex;padding:40rpx 50rpx;border-bottom:1px solid #eee;">
               <div class="fz" style="padding:0 20rpx 0 0rpx;color:#999">房屋地址</div>
               <div class="fz">{{TKaddress}}</div>
           </div>
            <uni-forms-item name="expendstate">
           
               <uni-data-checkbox @change='choose' selectedColor="#FFBD6C" selectedTextColor="#4A4A4A" v-model="formData.expendstate" :localdata="leaseMode" style="width:100%"/>     
            </uni-forms-item>
            <div style="width:100%;border-bottom:1px solid #ddd"  >
               <div style="margin-left:50rpx">
               <uni-forms-item  :label="daylong" name="jiaozuDate" :label-width="200">
                <uni-easyinput   type="number" :inputBorder="false" v-model="inputTime" placeholder="请输入" @input="timelong"/>
              </uni-forms-item>
            </div>
            </div>
           <div class="center" style="padding:30rpx 5rpx">
              <div class="getmima center" @click="nextPay(index)">下一步</div>
            </div>
          </uni-forms>
      </div>
    </uni-popup>
    <uni-popup ref="popup9" type="center">
     <div class="edit">
        <div class="close" @click="closePopup">
          <img v-if="baseUrl" :src="baseUrl + 'order/close.png'" alt="" srcset="" />
        </div>
        <div class="edit-top">充电费</div>
          <uni-forms ref="form" :modelValue="formData" :rules="rules">
           <div style="display:flex;padding:20rpx 50rpx;border-bottom:1px solid #eee;justify-content:space-between">
               <div class="fz" style="padding:0 20rpx 0 0rpx;color:#999">房屋地址</div>
               <div class="fz">{{TKaddress}}</div>
           </div>
            <div style="display:flex;padding:20rpx 50rpx;border-bottom:1px solid #eee;justify-content:space-between">
               <div class="fz" style="padding:0 20rpx 0 0rpx;color:#999">电费余量</div>
               <div class="fz" >{{electricitybalance}}度</div>
           </div>
            <div style="display:flex;padding:20rpx 50rpx;border-bottom:1px solid #eee;justify-content:space-between">
               <div class="fz" style="padding:0 20rpx 0 0rpx;color:#999">电费单价</div>
               <div class="fz">{{electricityfees}}元/度</div>
           </div>
            <div style="display:flex;padding:20rpx 50rpx;border-bottom:1px solid #eee;justify-content:space-between">
               <div class="fz">充值金额</div>
               <div class="fz" style="padding:0 20rpx 0 0rpx;color:#999;">
                 <input type='number' placeholder="请输入充值金额" style="text-align:right"  @input="search($event)" v-model="inputValue"></input>
               </div>
           </div>
           <div class="center" style="padding:30rpx 5rpx" >
              <div class="getmima center" @click="clickPay">去支付</div>
            </div>
          </uni-forms>
      </div>
    </uni-popup>
     <uni-popup ref="popup10" type="center">
     <div class="edit">
        <div class="close" @click="closePopup">
          <img v-if="baseUrl" :src="baseUrl + 'order/close.png'" alt="" srcset="" />
        </div>
        <div class="edit-top">联系管家</div>
           <div style="width:100%;display:flex; justify-content: space-between;padding: 10rpx 40rpx;border:1rpx solid #eee" v-for="(item,index) in houseKeeperList" :key="item.telphone">
                <div style="display:flex">
                    <div>
                      <img :src="item.avatar" alt="" style="width:60px;height:60px;border-radius:50%">
                    </div>
                    <div style="line-height:2;margin-top:2rpx">
                        <p style="margin-left:20rpx;font-weight:800;font-size:30rpx">{{item.unickname}}</p>
                        <p style="margin-left:20rpx;color:#999;font-weight:800;">{{item.telphone}}</p>
                    </div>
                </div>
                <div style="line-height:4.8" >
                 <img :src="baseUrl+'twoicon/phone.png'" @click="callguanjia(item.telphone)" alt="" style="width:40rpx;height:40rpx">
                </div>
           </div>
      </div>
    </uni-popup>
  </div>
</template>

   
<script>
// const yezhuduan = imgUrl+'home/yezhuduan.png'
// const rightgly = imgUrl+'home/rightgly.png'
import { GetBanner, TenantDefault, TenantDefaultTwo, GetPowerInfo, CreatePowerOrder, AddNoFlexibleNext, AddFlexibleNext, createPayment } from '@/apis/tenant/home'
import { getLockPassword, openDoorSave } from '@/apis/opendoor'
import { ChangeUserType } from '@/apis/user'
import { setToken } from '@utils/auth'
import store from '@store/index'
import { GethousekeeperListV2 } from '@/apis/tenant/leases'
import dingyue from '../../test/index.vue'
var smartLock = requirePlugin('smartLock')

import { bluetooth_lock } from '@utils/lockConfig'
export default {
  components: {
    dingyue
  },
  data() {
    return {
      interstitialAd: null,
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 500,
      timeOver: false,
      bannerList: null,
      tenantInfo: null,
      password: '',
      itemInfo: null,
      candidates: ['租客', '管理员', '业主'],
      userType: '租客',
      isshowtype: false,
      powersn: false,
      roommate: '0',
      electricitybalance: 0, //剩余电量
      TKaddress: '', //充电费弹框内的地址
      electricityfees: '0', //电费单价
      daylong: '交租时长',
      wid: null, //合同id
      inputValue: null, //充值金额
      dailyrent: '', //日租金
      monthlyrent: '', //月租金
      quarterlyrent: '', //季租金
      weeklyrent: '', //周租金
      cycle: '0', //交租方式
      firstrentpayment: null, //首次交租时间
      inputTime: null,
      phone: '',
      payrenttype: '', //0线上交租 1线下交租
      houseKeeperList: '', //管家
      houseid: '',
      orderText: '',
      onLineFlag: '', //线上支付 0-是 1-否
      tenantInfoTwo: '',
      paywidid: '',
      swiperIndex: '', // leaseMode:[
      //   {
      //     value: '0',
      //     text: ''
      //   },
      //   {
      //     value: '1',
      //    text: ''
      //   },
      //   {
      //     value: '2',
      //     text: ''
      //   },
      //   {
      //     value: '3',
      //    text: ''
      //   }
      // ]
      leaseMode: [
        { value: 0, text: '日付租金（1000/日）' },
        { value: 1, text: '周付租金（1000/周）' },
        { value: 2, text: '月付租金（1000/月）' },
        { value: 3, text: '季付租金（1000/3个月）' }
      ]
    }
  },

  onShow() {
    this.GetBanner()
    this.TenantDefault()
    this.TenantDefaultTwo()
  },
  created() {
    this.GetBanner()
    this.TenantDefault()
    this.TenantDefaultTwo()
    console.log(this.$store.state.baseStore.userInfo)
    setTimeout(() => {
      console.log(this.tenantInfo)
    }, 3000)
    this.get_wx_access_token()
    setTimeout(() => {
      // this.notice()
    }, 3000)
  },
  computed: {
    userInfo() {
      return this.$store.state.baseStore.userInfo
    },
    baseUrl() {
      return process.env.VUE_APP_BASE_IMG_URL
    },
    isnone() {
      if (this.tenantInfo) {
        return this.tenantInfo.length
      } else {
        return false
      }
    }
  },
  methods: {
    choose(e) {
      this.firstrentpayment = e.detail.value
      this.orderText = e.detail.data.text
      console.log(this.firstrentpayment)
      if (e.detail.value == 0) {
        this.daylong = '交租时长(日)'
      } else if (e.detail.value == 1) {
        this.daylong = '交租时长(周)'
      } else if (e.detail.value == 2) {
        this.daylong = '交租时长(月)'
      } else if (e.detail.value == 3) {
        this.daylong = '交租时长(季)'
      }
    },
    //      get_wx_access_token() {
    //        let appid ='wx30089e25b0b08834'
    //        let secret= '586d3c4c0cf67ecbf5990866cfcb6fc7'
    //     return uni.request({
    //         method: 'get',
    //         url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
    //         dataType: 'json',
    //         timeout: 30000
    //     }).then(res => {
    //         let [err, success] = res
    //         if (success.statusCode == 200) {
    //           console.log(success.data.access_token)
    //           this.acc_token= success.data.access_token
    //             return success.data.access_token
    //         }
    //     })
    // },
    // 通知
    notice() {
      let self = this
      //下方的thing1，thing2和其他，对应的是你选取模板的模板详情中的字段名称(可在小程序后台模板查看对应的字段，要和上面的字段一样)，需要更改成你自己的
      const pushmsg = {
        touser: this.$store.state.baseStore.userInfo.openid,
        template_id: '48y4VNZO7YvZw_NHgWLT6WSJrR9OoECrBwHPKrzM2Uc',
        page: 'pages/index/index',
        data: {
          thing1: {
            value: '预约项目'
          },
          time2: {
            value: '2019-12-26 16:00'
          },
          thing3: {
            value: '客户名称'
          },
          phone_number4: {
            value: '19941773278'
          },
          thing6: {
            value: '服务地点'
          }
        }
      }
      wx.request({
        url: 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' + this.acc_token,
        data: JSON.stringify(pushmsg),
        method: 'POST',
        miniprogram_state: 'formal', //developer为开发版；trial为体验版；formal为正式版；非必传
        success: function (res) {
          console.log(res)
        }
      })
    },
    showType() {
      this.isshowtype = !this.isshowtype
    },
    jiaozu(index) {
      this.GetPowerInfo(index)
      this.$refs.popup8.open()
    },
    closePopup() {
      this.$refs.popup8.close()
      this.$refs.popup9.close()
      this.$refs.popup10.close()
    },
    dianfei(index) {
      this.GetPowerInfo(index)
       this.$refs.popup9.open()
    },
    checkType(int) {
      let that = this
      // store.commit('baseStore/SET_USERTYPE', int)
      // uni.redirectTo({ url: '/pages/index/index' })

      ChangeUserType({ userid: that.userInfo.userid, type: int })
        .then((e) => {
          if (e.code == 200) {
            wx.setStorageSync('sysUserInfo', JSON.stringify(e.data))
            setToken(e.data.token)
            store.commit('baseStore/SET_USERINFO', e.data)
            // that.$jump({path: '/pages/index/index'})
            uni.redirectTo({ url: '/pages/index/index' })
          }
        })
        .catch((e) => {
          console.log(e)
        })
    },
    call() {
      this.$refs.popup10.open()
      // uni.makePhoneCall({
      //   phoneNumber: this.phone,
      //   success: function () {
      //     console.log('拨打电话成功')
      //   },
      //   fail() {
      //     console.log('打电话失败了')
      //   }
      // })
    },
    callguanjia(phone) {
      uni.makePhoneCall({
        phoneNumber: phone,
        success: function () {
          console.log('拨打电话成功')
        },
        fail() {
          console.log('打电话失败了')
        }
      })
    },
    GetBanner() {
      GetBanner().then((res) => {
        if (res.code == 200) {
          this.bannerList = res.data
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    TenantDefault() {
      TenantDefault({ userid: this.userInfo.userid, type: 0 }).then((res) => {
        if (res.code == 200) {
          this.tenantInfo = res.data
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    TenantDefaultTwo() {
      TenantDefaultTwo({ userid: this.userInfo.userid, type: 0 }).then((res) => {
        if (res.code == 200) {
          this.tenantInfoTwo = res.data
          console.log(this.tenantInfo)
          console.log(this.tenantInfoTwo)
          this.phone = res.data[0].telphone
          this.electricitybalance = res.data[0].electricitybalance //剩余电量余额
          this.wid = res.data[0].wid
          this.cycle = res.data[0].cycle
          this.payrenttype = res.data[0].payrenttype
          this.houseid = res.data[0].houseid
          this.getguanjia()
          if (res.data[0].powersn) {
            this.powersn = true
          } else {
            this.powersn = false
          }
          if (res.data[0].roommate == '0') {
            this.roommate = 0
          } else {
            this.roommate = 1
          }
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    GetPowerInfo(index) {
      //点击充电费
      console.log(index)
      this.swiperIndex = index
      GetPowerInfo({ contractid: this.tenantInfoTwo[index].wid }).then((res) => {
        if (res.data.onLineFlag == 1) {
          uni.showToast({
            title: '该用户未开通线上支付，请联系管理员',
            icon: 'none',
            duration: 2000
          })
          return
        }
        // this.$refs.popup9.open()
        console.log(res)
        if (res.code == 200) {
          if (!this.leaseMode[0]) {
            this.leaseMode[0].text = '日付租金（' + res.data.dailyrent + '元/日）'
          }
          if (!this.leaseMode[1]) {
            this.leaseMode[1].text = '周付租金（' + res.data.weeklyrent + '元/周）'
          }
          if (!this.leaseMode[2]) {
            this.leaseMode[2].text = '月付租金（' + res.data.monthlyrent + '元/月）'
          }
          if (!this.leaseMode[3]) {
            this.leaseMode[3].text = '季付租金（' + res.data.quarterlyrent + '/3个月）'
          }
          this.TKaddress = res.data.address
          this.electricityfees = res.data.electricityfees

          if (this.leaseMode[0]) {
            this.leaseMode[0].text = '日付租金（' + res.data.dailyrent + '元/日）'
          }
          if (this.leaseMode[1]) {
            this.leaseMode[1].text = '周付租金（' + res.data.weeklyrent + '元/周）'
          }
          if (this.leaseMode[2]) {
            this.leaseMode[2].text = '月付租金（' + res.data.monthlyrent + '元/月）'
          }
          if (this.leaseMode[3]) {
            this.leaseMode[3].text = '季付租金（' + res.data.quarterlyrent + '元/3个月）'
          }
          console.log(res.data)
          if (res.data.quarterlyrent == 0) {
            console.log(0)
            this.leaseMode.splice(3, 1)
          }
          if (res.data.monthlyrent == 0) {
            this.leaseMode.splice(2, 1)
            console.log(1)
          }
          if (res.data.weeklyrent == 0) {
            this.leaseMode.splice(1, 1)
            console.log(2)
          }
          if (res.data.dailyrent == 0) {
            this.leaseMode.splice(0, 1)
            console.log(3)
          }
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
        console.log(this.leaseMode)
      })
    },
    clickPay() {
      console.log('11313')
      this.CreatePowerOrder()
    },
    search(event) {
      this.inputValue = event.detail.value
      const inputRule = /^(0+)|[^\d]+/g
      this.$nextTick(function () {
        this.inputValue = this.inputValue.replace(inputRule, '')
      })
    },
    timelong(e) {
      this.inputTime = e
      const inputRule = /^(0+)|[^\d]+/g
      this.$nextTick(function () {
        this.inputTime = this.inputTime.replace(inputRule, '')
      })
    },
    getguanjia() {
      GethousekeeperListV2({
        Contractid: this.wid,
        house_room_id: this.houseid
      }).then((e) => {
        if (e.code === 200) {
          this.houseKeeperList = e.data
          console.log(this.houseKeeperList)
        }
      })
    },
    //点击支付
    CreatePowerOrder() {
      if (this.inputValue == '' || this.inputValue == null) {
        uni.showToast({
          title: '请输入充值金额',
          icon: 'none',
          duration: 2000
        })
        return
      }

      console.log(this.tenantInfoTwo)
      console.log(this.tenantInfoTwo[this.swiperIndex])
      const data = {
        contractid: this.tenantInfoTwo[this.swiperIndex].wid,
        totalprice: this.inputValue,
        userid: this.userInfo.userid
      }
      CreatePowerOrder(data).then((res) => {
        if (res.code == 200) {
          const orderno = res.data.orderno
          const totalprice = res.data.totalprice.toFixed(2)
          const title = '电费充值'
          const openid = wx.getStorageSync('openid')

          createPayment({
            goods_desc: 'ceshi',
            goods_title: title,
            openid,
            orderno: orderno,
            payamt: totalprice
          }).then((res) => {
            console.log(res)
             if(res.code == '500'){
                  uni.showToast({
                    title: res.msg,
                    icon: 'none'
                  })
                  return
                }
            const { timeStamp, nonceStr, package: pack, paySign, signType } = JSON.parse(res.data.expend.pay_info)
            wx.requestPayment({
              timeStamp,
              nonceStr,
              package: pack,
              signType,
              paySign,
              success: function (res) {
                console.log(res)
              },
              fail: function (res) {},
              complete: function (res) {}
            })
          })
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    //灵活交租弹窗下一步
    nextPay() {
      console.log(this.swiperIndex)
      if (this.inputTime == '' || this.inputTime == null || !this.inputTime) {
        uni.showToast({
          title: '请输入交租时长',
          icon: 'none',
          duration: 2000
        })
        return
      }
      if (this.firstrentpayment == null) {
        uni.showToast({
          title: '请选择交租模式',
          icon: 'none',
          duration: 2000
        })
        return
      }

      AddFlexibleNext({ contractid: this.tenantInfoTwo[this.swiperIndex].wid, duration: this.inputTime, firstrentpayment: this.firstrentpayment }).then((res) => {
        if (res.code == 200) {
          console.log(res.data)
          this.jump_empowerendtime = res.data.empowerendtime
          this.jump_endtime = res.data.endtime
          this.jump_payprice = res.data.payprice
          this.jump_mortgage = res.data.mortgage
          this.jump_rate = res.data.rate
          this.jump_rent = res.data.rent
          this.jump_orderno = res.data.orderno
          TenantDefaultTwo({ userid: this.userInfo.userid, type: 0 }).then((res) => {
            //  let houseid =res.data[0].houseid
            //  let wid  = res.data[0].wid
            //  let querry = {
            //    "wid":wid,
            //    'houseid':houseid,
            //    "state": 1
            //  }
            let querry = res.data[this.swiperIndex]
            console.log(querry)
            querry.jump_empowerendtime = this.jump_empowerendtime
            querry.jumpAdd = 'jiaozu'
            querry.jump_endtime = this.jump_endtime
            querry.jump_mortgage = this.jump_mortgage
            querry.jump_payprice = this.jump_payprice
            querry.jump_rate = this.jump_rate
            querry.jump_rent = this.jump_rent
            querry.jump_orderText = this.orderText
            querry.jump_daylong = this.daylong
            querry.jump_orderno = this.jump_orderno
            querry.jump_daylongValue = this.inputTime + (this.firstrentpayment == 0 ? '日' : this.firstrentpayment == 1 ? '周' : this.firstrentpayment == 2 ? '个月' : '季')
            console.log(querry)
            this.$jump({ path: '/pages/tenant/lease/detaillease?query=' + JSON.stringify(querry) })
            this.$refs.popup8.close()
            this.$refs.popup9.close()
          })
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    //非灵活交租点击缴费
    jiaozu2(index) {
      console.log('131313')
      this.swiperIndex = index
      AddNoFlexibleNext({ contractid: this.tenantInfoTwo[index].wid, userid: this.userInfo.userid }).then((res) => {
        if (res.code == 200) {
          this.jump_endtime = res.data.endtime
          this.jump_empowerendtime = res.data.empowerendtime
          this.jump_payprice = res.data.payprice
          this.jump_mortgage = res.data.mortgage
          this.jump_rate = res.data.rate
          this.jump_rent = res.data.rent

          TenantDefaultTwo({ userid: this.userInfo.userid, type: 0 }).then((res) => {
            //  let houseid =res.data[0].houseid
            //  let wid  = res.data[0].wid
            //  let querry = {
            //    "wid":wid,
            //    'houseid':houseid,
            //    "state": 1
            //  }
            let querry = res.data[index]

            querry.jumpAdd = 'jiaozu'
            querry.jump_empowerendtime = this.jump_empowerendtime
            querry.jump_endtime = this.jump_endtime
            querry.jump_mortgage = this.jump_mortgage
            querry.jump_payprice = this.jump_payprice
            querry.jump_rate = this.jump_rate
            querry.jump_rent = this.jump_rent
            querry.jump_orderText = this.orderText
            querry.jump_daylong = this.daylong
            querry.jump_daylongValue = this.inputTime
            console.log(querry)
            this.$jump({ path: '/pages/tenant/lease/detaillease?query=' + JSON.stringify(querry) })
            this.$refs.popup8.close()
            this.$refs.popup9.close()
          })
          //  TenantDefaultTwo({userid: this.userInfo.userid,type:0}).then(res => {
          //    let querry = JSON.stringify(res.data[0])
          //    console.log(querry)
          //   querry.jumpAdd = 'jiaozu'
          //   this.$jump({ path: '/pages/tenant/lease/detaillease?query=' + querry})
          //  })
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    // CreatePowerOrder
    checkBanner(item) {
      uni.redirectTo({ url: '/componentsMine/webview?url=' + item.url })
      // this.$jump({path:"/componentsMine/webview?url="+item.url})
    },
    makePhone(phone) {
      uni.makePhoneCall({
        phoneNumber: phone, //仅为示例
        success: (res) => {},
        fail: (err) => {
          uni.showToast({
            title: '拨打失败',
            icon: 'none'
          })
        }
      })
    },
    gotocheck(item) {
      //  if(wx.createInterstitialAd){
      //   this.interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-b7624e2779b6167a' })
      //   this.interstitialAd.onLoad(() => {
      //     console.log('onLoad event emit')
      //   })
      //   this.interstitialAd.onError((err) => {
      //     console.log('onError event emit', err)
      //   })
      //   this.interstitialAd.onClose((res) => {
      //     console.log('onClose event emit', res)
      //   })
      //  }
      // console.log('oppasdioasdisaodhjiasjdoias')
      // this.interstitialAd.show().then().catch(err => {
      //   console.log(err)
      // })
      this.itemInfo = item
      if (item.roomlocknumber) {
        this.$refs.popup1.open()
      } else {
        this.getPassword(0)
      }
    },
    closePupop(id) {
      // this.$refs.checkPassword.close()
      switch (id) {
        case 0:
          this.$refs.popup.close()
          break
        case 1:
          this.$refs.popup1.close()
          break
        case 2:
          this.$refs.popup2.close()
          break
        case 3:
          this.$refs.popup3.close()
          break
        case 4:
          this.$refs.popup4.close()
          break
        case 5:
          this.$refs.popup5.close()
          break
        case 6:
          this.$refs.popup6.close()
          break
        case 7:
          this.$refs.popup7.close()
          break
      }
    },
    isfictitious(int) {
      let isflag = int ? this.itemInfo.roomisfictitious : this.itemInfo.bigisfictitious
      if (isflag) {
        this.$refs.popup7.open()
        this.$refs.popup1.close()
        return true
      } else {
        return false
      }
    },
    openDoor(int, item) {
      // const deviceId = '684B8333'
      // const devicePsw = '95613290'
      // const sDeviceId = 'C3:12:68:4B:83:33'
      // const sDeviceType = 'null'
      // const sDeviceTypeTemp = ''

      //  var tStr = smartLock.buildBindDevice(deviceId, devicePsw,sDeviceId,sDeviceType,sDeviceTypeTemp);
      // smartLock.operateLockNoLoading('C3:12:68:4B:83:33',11,tStr,function(){

      // })

            if (this.$store.state.baseStore.userInfo.usertype == 0) { 
      if(wx.createInterstitialAd){
        this.interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-126d702f60e9da4a' })
        this.interstitialAd.onLoad(() => {
          console.log('onLoad event emit')
        })
        this.interstitialAd.onError((err) => {
          console.log('onError event emit', err)
        })
        this.interstitialAd.onClose((res) => {
          console.log('onClose event emit', res)
        })
      }
      this.interstitialAd.show().then().catch(err => {
        console.log(err)
      })
    }

      let that = this
      this.itemInfo = item
      let isflag = this.isfictitious(int)
      if (isflag) return
      smartLock.initSmartLock(bluetooth_lock.appid, bluetooth_lock.appkey, bluetooth_lock.user, bluetooth_lock.password, (res) => {
        // let id = item.houseid;//房源ID
        let tLockId = int ? item.roomlocknumber : item.locknumber //设备号
        // this.data.unlock_number = unlocknumber;
        if (res.data.result === 0) {
          // 检测开门权限
          //需要initSmartLockPlus回调成功后才有效调用开锁接口
          smartLock.openCloseBleLock(tLockId, 1, function (res) {
            if (res.data.result == 0) {
              that.$refs.popup2.open()
              that.openDoorSave(1, int)
            } else {
              that.$refs.popup4.open()
              that.openDoorSave(0, int)
            }
          })
        }
      })
    },
    openDoorSave(int, type) {
      let data = {
        houseid: this.itemInfo.houseid,
        houseroomid: this.itemInfo.houseroomid,
        state: int,
        userid: this.userInfo.userid,
        type: type
      }
      console.log(data)
      openDoorSave(data).then((res) => {
        console.log('set open door info', res)
      })
    },
    getPassword(int) {
     
      let isflag = this.isfictitious(int)
      if (isflag) return
      const data = {
        locknumber: int ? this.itemInfo.roomlocknumber : this.itemInfo.locknumber
      }
      getLockPassword(data).then((res) => {
        if (res.code == 200) {
          this.password = res.data
          this.$refs.popup3.open()
          this.closePupop(1)
        } else {
          this.closePupop(1)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.edit {
  width: 335px;
  // height: 584px;
  box-sizing: border-box;
  background: #ffffff;
  border-radius: 4px;
  .close {
    position: absolute;
    top: 22px;
    right: 15px;
    width: 18px;
    height: 18px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .edit-top {
    height: 60px;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #4a4a4a;
    line-height: 60px;
    text-align: center;
    border-bottom: 1px solid #eee;
  }
}
.tenantHome {
  width: 100vw;
  box-sizing: border-box;
  .none {
    // width: 100vw;
    margin-top: 40px;
    background: #f9f9f9;
    // background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img {
      width: 190px;
      height: 195px;
    }
  }
  .tenantSwiper {
    width: 100%;
    height: 180px;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    .swiper {
      width: 345px;
      height: 150px;
      .swiper-item {
        width: 345px;
        height: 150px;
        box-shadow: 0px 6px 6px 0px rgba(0, 0, 0, 0.1);
        border-radius: 8px;
      }
    }
  }
  .user-infor {
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding: 10px 15px;
    margin: 10px;
    background-color: #fff;
    .left1 {
      display: flex;
      align-items: center;
    }
    .user {
      img {
        width: 60px;
        height: 60px;
        border-radius: 50%;
      }
    }
    .center {
      margin: 0 57px 0 15px;
      div {
        height: 25px;
        font-size: 20px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 25px;
      }
      img {
        width: 50px;
        height: 20px;
        margin-top: 10px;
      }
    }
    .right {
      position: relative;
      img {
        width: 96px;
        height: 36px;
      }
      .rightType {
        position: absolute;
        top: 37px;
        right: 0;
        z-index: 100;
        div {
          width: 96px;
          height: 36px;
          background: #fbaf53;
          color: #fff;
          border-radius: 50px;
          text-align: center;
          line-height: 36px;
          font-size: 15px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 200;
        }
        .one {
          margin-bottom: 2px;
        }
      }
    }
  }
  .tenant-content {
    margin: 10px;
    margin-top: 0;
    background: #fff;
    position: relative;
    .content-swiper {
      height: 405px;
    }
    .content-top {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      box-sizing: border-box;
      padding: 0 15px;
      height: 64px;
      border-bottom: 1px solid #efefef;
      .flex {
        display: flex;
        align-items: center;
      }
      .address-imag {
        img {
          width: 20px;
          height: 20px;
        }
      }
      .address {
        margin: 0 0 0 10px;
        // width: 166px;
        font-size: 30rpx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 22px;
        word-break: break-all;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
      .typeBtn {
        display: flex;
        flex-direction: column;
        align-items: center;
        img {
          width: 21px;
          height: 21px;
        }
        .wenzi {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #4a4a4a;
          line-height: 20px;
          margin-top: 3px;
        }
        .wid28 {
          width: 28px;
        }
        .wid56 {
          width: 56px;
        }
      }
      .marginright {
        margin-right: 15px;
      }
    }
    .centent-center {
      position: relative;
      .last {
        margin-top: 15px;
        text-align: center;
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #9b9b9b;
        line-height: 24px;
      }
      .power {
        position: absolute;
        right: 10px;
        top: 4px;
        width: 42px;
        height: 17px;
        display: flex;
        justify-content: center;
        align-items: center;
        .chi {
          width: 40px;
          font-size: 10px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          color: #1cdf7c;
          line-height: 17px;
          text-align: center;
          border: 1px solid #1cdf7c;
          position: relative;
          border-radius: 2px;
          .jindu {
            position: absolute;
            top: 1px;
            left: 1px;
            background: rgba(28, 223, 124, 0.3);
            height: 15px;
            z-index: 0;
          }
        }
        .shu {
          width: 2px;
          height: 10px;
          background: #1cdf7c;
          margin-left: 1px;
        }
      }
      .nopower {
        .chi {
          color: #ef1e13;
          border: 1px solid #ef1e13;
          .jindu {
            background: rgba(239, 30, 19, 0.3);
          }
        }
        .shu {
          background: #ef1e13;
        }
      }
      .last-time {
        text-align: center;
        font-size: 50px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #1cdf7c;
        // line-height: 50px;
        span {
          font-size: 22px;
        }
      }
      .redcolor {
        color: #ef1e13;
      }
      .open-door {
        display: flex;
        justify-content: center;
        align-items: center;
        .openB {
          width: 169px;
          height: 169px;
        }
        .openS {
          width: 149px;
          height: 149px;
        }
      }
    }
    .getpassword {
      display: flex;
      justify-content: center;
      align-items: center;
      .getmima {
        width: 104px;
        height: 40px;
        background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
        box-shadow: 0px 2px 4px 0px rgba(252, 174, 55, 0.21), 0px 3px 5px 0px rgba(255, 216, 111, 0.14);
        border-radius: 100px;
        font-size: 16px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #ffffff;
        line-height: 40px;
        text-align: center;
        text-shadow: 0px 2px 4px rgba(252, 174, 55, 0.21);
      }
    }
  }
  .getmima {
    width: 75%;
    height: 40px;
    background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
    box-shadow: 0px 2px 4px 0px rgba(252, 174, 55, 0.21), 0px 3px 5px 0px rgba(255, 216, 111, 0.14);
    border-radius: 100px;
    font-size: 16px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #ffffff;
    line-height: 40px;
    text-align: center;
    text-shadow: 0px 2px 4px rgba(252, 174, 55, 0.21);
  }
  .checkPassword {
    width: 335px;
    height: 210px;
    background: #ffffff;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    // justify-content: center;
    align-items: center;
    position: relative;
    .close {
      position: absolute;
      top: 22px;
      right: 15px;
      width: 18px;
      height: 18px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .top {
      width: 100%;
      height: 60px;
      text-align: center;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4a4a4a;
      line-height: 60px;
      border-bottom: 1px solid #efefef;
    }
    .bigBtn {
      margin: 20px 0;
      width: 305px;
      height: 45px;
      background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
    }
    .smalBtn {
      width: 305px;
      height: 45px;
      background: linear-gradient(140deg, #ffcf58 0%, #ffd758 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
    }
  }
  .open-success {
    width: 335px;
    height: 373px;
    background: #27c58d;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img {
      margin-top: 44px;
      width: 259px;
      height: 137px;
    }
    .text1 {
      height: 53px;
      font-size: 38px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 53px;
      margin: 15px 0 6px 0;
      text-align: center;
    }
    .text2 {
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
      line-height: 22px;
      text-align: center;
    }
    button {
      margin-top: 20px;
      width: 305px;
      height: 45px;
      background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
    }
    button::after {
      border: 0;
    }
  }
  .mima-success {
    width: 335px;
    height: 467px;
    background: #27c58d;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img {
      width: 259px;
      height: 137px;
    }
    .text1 {
      height: 67px;
      font-size: 48px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 67px;
      text-align: center;
      margin: 24px 0 9px 0;
    }
    .text2 {
      width: 283px;
      height: 44px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
      line-height: 22px;
      text-align: center;
    }
    .btn1 {
      width: 305px;
      height: 45px;
      background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
      margin: 24px 0 10px 0;
    }
    .btn2 {
      width: 305px;
      height: 45px;
      border-radius: 100px;
      border: 1px solid #ffffff;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      background-color: #27c58d;
    }
    button::after {
      border: 0;
    }
  }
  .lanya {
    width: 335px;
    height: 373px;
    border-radius: 10px;
    background: #d84243;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img {
      width: 117px;
      height: 115px;
    }
    .text {
      font-size: 28px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 40px;
      text-align: center;
    }
    .text1 {
      margin-top: 38px;
    }
    .btn1 {
      margin-top: 31px;
      width: 305px;
      height: 45px;
      background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
    }
    .btn1::after {
      border: 0;
    }
  }
  .lanya2 {
    width: 335px;
    height: 373px;
    border-radius: 10px;
    background: #fff;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img {
      width: 117px;
      height: 115px;
    }
    .text {
      font-size: 20px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4a4a4a;
      line-height: 30px;
      text-align: center;
      padding: 0 10px;
    }
    .text1 {
      margin-top: 38px;
    }
    .btn1 {
      margin-top: 31px;
      width: 305px;
      height: 45px;
      background: linear-gradient(315deg, #ffaa58 0%, #ffbd6c 100%);
      border-radius: 100px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 45px;
      text-align: center;
    }
    .btn1::after {
      border: 0;
    }
  }
}
.flex {
  display: flez;
}
.k20 {
  width: 100%;
}
.k33 {
  width: 33%;
}
.around {
  justify-content: space-around;
}
.textCenter {
  text-align: center;
}
.textStyle {
  font-size: 22rpx;
  color: #999;
}
.dianbao {
  position: absolute;
  padding: 10rpx 0 0 50rpx;
}
.dianfeiyue {
  color: #1782d2;
  position: absolute;
  text-align: center;
  // padding: 23rpx;
  font-size: 29rpx;
  font-weight: 800;
  width: 120rpx;
  padding-top: 23rpx;
}
.fz {
  font-size: 29rpx;
}

.uni-data-checklist {
  font-size: 30px !important;
}
.checklist-box .radio__inner {
  margin-left: 50rpx !important;
}
.center {
  margin: 0 auto;
}

.checkbox ::v-deep .uni-forms {
  .uni-forms-item {
    .uni-forms-item__box {
      .uni-forms-item__inner {
        margin: 0 !important;
        padding: 0 !important;
      }
    }
  }
}
// .tenantHome ::v-deep .uni-forms{
//    .uni-forms-item{
//      .uni-forms-item__box{
//         .uni-forms-item__inner{
//         margin: 0 !important;
//         padding: 0 !important;
//       }
//      }
//    }
// }
/*
.uni-data-checklist .checklist-group .checklist-box{
  padding: 20rpx 0 25rpx 0 !important;
  margin-right: 0 !important
}
.uni-data-checklist .checklist-group .checklist-box .checklist-content .checklist-text{
  font-size: 30px;
  font-weight: 800;
  color:black;
}

.uni-data-checklist .checklist-group .checklist-box{
  border-bottom: 1px solid #ddd;
  border-color: #ddd !important;
  width:100%
}
.uni-data-checklist .checklist-group .checklist-box .radio__inner {
  margin-left:50rpx
}
.uni-forms-item__inner {
  padding-bottom : 0 !important;
}
.uni-forms-item__label .label-text {
  font-size: 30rpx !important;
  color:black;
  font-weight: 900;
}
*/
</style>
